package cn.itcast.nems.order.service.impl;

import cn.itcast.nems.common.utils.BigDecimalUtil;
import cn.itcast.nems.order.dao.entity.PaymentReceipt;
import cn.itcast.nems.order.dao.mapper.PaymentReceiptMapper;
import cn.itcast.nems.order.service.PaymentReceiptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * <p>
 * 支付收据 服务实现类
 * </p>
 *
 * @author liyong
 * @since 2023-08-31
 */
@Slf4j
@Service
@AllArgsConstructor
public class PaymentReceiptServiceImpl extends ServiceImpl<PaymentReceiptMapper, PaymentReceipt> implements PaymentReceiptService {
    private final PaymentReceiptMapper paymentReceiptMapper;

    @Override
    public Map<String, Object> getPaymentReceipt(String paymentFlowId) {
        Assert.hasText(paymentFlowId, "paymentFlowId 不能为空");
        Map<String, Object> paymentReceipt = paymentReceiptMapper.getPaymentReceipt(paymentFlowId);
        if (paymentReceipt == null) {
            return paymentReceipt;
        }
        if (paymentReceipt.get("original_amount") != null) {
            double amountUpperCase = Double.parseDouble(paymentReceipt.get("original_amount").toString());
            paymentReceipt.put("amount_upper_case", BigDecimalUtil.amountUpperCase(amountUpperCase/100));
        }
        return paymentReceipt;
    }
}
